package com.leo.lime.music.controller;

import android.content.Context;
import android.content.SharedPreferences;

import com.leo.lime.music.utils.Utils;

/**
 * Created by android on 18-8-13.
 */

public class SharedPrefController {
    private static final String TAG = "SharedPrefController";

    private Context mContext;
    private static SharedPrefController mController;
    private SharedPreferences mSharedPrefs;

    private SharedPrefController(Context ctx) {
        mContext = ctx.getApplicationContext();
        mSharedPrefs = mContext.getSharedPreferences(Utils.SharedPrefs.SHARED_PREFS_NAME, Utils.SharedPrefs.SHARED_PREFS_MODE);
    }

    public static SharedPrefController getInstance(Context ctx) {
        if(mController == null) {
            mController = new SharedPrefController(ctx);
        }
        return mController;
    }

    public void setContentPagerIndex(int index) {
        if(mSharedPrefs != null) {
            mSharedPrefs.edit().putInt(Utils.SharedPrefs.CONTENT_PAGER_INDEX, index).apply();
        }
    }

    public int getContentPagerIndex() {
        return mSharedPrefs.getInt(Utils.SharedPrefs.CONTENT_PAGER_INDEX, Utils.SharedPrefs.DEFAULT_CONTENT_PAGER_INDEX);
    }
}
